<html>
<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <link href="${ctx}/wangEditor/3.1.1/wangEditor.min.css" rel="stylesheet">
    <script src="${ctx}/wangEditor/10.0.13/wangEditor.min.js"></script>
    <script src="${ctx}/js/iw.js"></script>
    <link href="${ctx}/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet">
    <script src="${ctx}/bootstrap-switch/js/bootstrap-switch.min.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">

    <style>
        /*标准色—红色*/
        .c-red, .c-red a, a.c-red {
            color: red
        }
    </style>

</head>
<body>
<input type="file" id="file1" onchange="loadpic(this.files)" style="display: none">
<br><br><br>
<form class="layui-form" action="" lay-filter="item" style="width: 500px;margin: 0 auto;overflow-x: hidden">
    <input type="hidden" name="id" value="${item.id!''}">
    <input type="text" style="display:none;" id="multiwordId" name="multiwordId" value="${item.multiwordId!''}"/>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>搜索关键词</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" maxLength="16" placeholder="请输入字段名称"
                   autocomplete="off" class="layui-input" value="${item.name!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>每日量</label>
        <div class="layui-input-block">
            <input type="number" name="amount" required lay-verify="required" maxLength="16"
                   placeholder="0代表每日不限量,若设置了执行计划则该值读取执行计划的每日量"
                   autocomplete="off" class="layui-input" value="${item.amount!0}">
        </div>
        <span class="c-red"> 注意：设置了执行计划后改为读取当天执行计划的每日量,若当天没有执行计划则当天没有任务</span>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>总量</label>
        <div class="layui-input-block">
            <input type="number" name="total" required lay-verify="required" maxLength="16"
                   placeholder="0代表每日不限量,若设置了执行计划则该值读取执行计划的每日量"
                   autocomplete="off" class="layui-input" value="${item.total!0}">
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>排名</label>
        <div class="layui-input-block">
            <input type="number" name="ranking" required lay-verify="required" maxLength="16" placeholder="app排名"
                   autocomplete="off" class="layui-input" value="${item.ranking!1}">
        </div>

    </div>


    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>跳转app市场链接</label>
        <div class="layui-input-block">
            <input type="text" name="skipUrl" required lay-verify="required" maxLength="150" placeholder="跳转app市场链接"
                   autocomplete="off" class="layui-input" value="${item.skipUrl!''}">
        </div>

    </div>

    <input type="hidden" class="form-control" id="icoUrl" name="icoUrl" readonly placeholder="图例"
           value="${item.icoUrl!''}">


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formUpdate">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


</form>
<div class="col-xs-11 col-xs-offset-1" id="_contents">
</div>

<script>
    var es = [];
    $(document).ready(function () {
        layui.use('form', function () {

            var form = layui.form;
            form.render();


            form.on('submit(formUpdate)', function (data) {
                /*  if(data.field.amount>data.field.total){
                      layer.msg("每日量不能大于总量!")
                      return false;
                  }*/
                $.ajax({
                    url: "speechinsert",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: data.field,    //参数值,键值对
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        if (req.success) {
                            parent.showmsg(req.message);
                            parent.reloadtable();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭

                        } else {
                            layer.msg(req.message)
                        }
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });

                return false;
            });
        });
        loadpicture();

    });

    function loadpicture() {
        $("#_contents").html("");
        var s = "<img style='width: 22%; height: auto; margin-right: 1%; border: 1px solid #ccc;' src='http://hotbb.repinchen.cn/upload_image.png' onclick='uplodafile()'/>";
        var src = "";
        var a = $('#icoUrl').val();
        if (a != '') {
            var b = a.split(',');
            for (let i = 0; i < b.length; i++) {
                src += "<img style='width: 22%; height: auto; margin-right: 1%; border: 1px solid #ccc;' src='" + b[i] + "' onclick='deletepicture(this)'/>";

            }


            // addImage()
        }
        src += s;
        $("#_contents").append(src);
    }

    function deletepicture(op) {
        layer.confirm('真的删除这张图片么', function (index) {
            layer.close(index);
            var a = $('#icoUrl').val();
            var b = a.split(',');
            for (let i = 0; i < b.length; i++) {
                if (b[i] === op.src) {
                    b.splice(op.src, 1);
                }
            }
            $('#icoUrl').val(b.toString());
            loadpicture();
        });


        // alert(op.src);

    }

    function uplodafile() {
        $('#file1').click();


    }

    function loadpic(files) {
        var file = files[0];

        // alert(files[0].type);
        var formData = new FormData();
        formData.append("file", file);
        $.ajax({
            url: '/upload',
            dataType: 'json',
            type: 'post',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (res) {

                var str = $('#icoUrl').val();
                if (str != '') {
                    str += "," + res.image;
                    $('#icoUrl').val(str);
                } else {
                    str += res.image;
                    $('#icoUrl').val(str);
                }

                loadpicture();
            },
            error: function (err) {
                alert(err.statusText);
            }
        })
    }


    function showmsg(msg) {
        layer.msg(msg)
    }

    function reloadtable() {
        table.bootstrapTable('refresh');
    }
</script>
</body>


</html>
